package com.example.administrator.jingpingou.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.widget.Toast;

import com.android.volley.Network;

/**
 * Created by Administrator on 2016/9/1 0001.
 */
public class MyBroadCastWifi extends BroadcastReceiver {
    NetworkInfo.State wifiState=null;
    NetworkInfo.State mobileState=null;


    @Override
    public void onReceive(Context context, Intent intent) {
        ConnectivityManager cm= (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        wifiState=cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
        mobileState=cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
//        Intent intent2=new Intent(context,Broa)
        if(wifiState!=null&&mobileState!=null&& NetworkInfo.State.CONNECTED!=wifiState&&
                NetworkInfo.State.CONNECTED==mobileState) {
            Toast.makeText(context, "手机网络连接成功", Toast.LENGTH_SHORT).show();
        }else if(wifiState!=null&&mobileState!=null&&
                NetworkInfo.State.CONNECTED==wifiState&&
                NetworkInfo.State.CONNECTED==mobileState){
            Toast.makeText(context, "无线网络连接成功", Toast.LENGTH_SHORT).show();

        }else if(wifiState!=null&&mobileState!=null&&
                NetworkInfo.State.CONNECTED!=wifiState&&
                NetworkInfo.State.CONNECTED!=mobileState){
            Toast.makeText(context, "手机没有任何网络", Toast.LENGTH_SHORT).show();
        }
    }
}
